package com.xjh.him.activity.chat;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.xjh.him.core.BaseActivity;
import com.xjh.him.databinding.ActivitySingleChatSettingBinding;
import com.xjh.him.dto.ChatPageSettingDTO;
import com.xjh.him.dto.friend.FriendDTO;
import com.xjh.him.utils.Utils;
import com.xuexiang.xui.widget.actionbar.TitleUtils;


public class ChatSingleSettingActivity extends BaseActivity<ActivitySingleChatSettingBinding> {
    public static final String KEY_FRIEND_DTO = "friendDTO";
    public static final String KEY_CHAT_PAGE_SETTING_DTO = "chatPageSettingDTO";

    private FriendDTO friendDTO;
    private ChatPageSettingDTO settingDTO;

    @Override
    protected ActivitySingleChatSettingBinding viewBindingInflate(LayoutInflater inflater) {
        return ActivitySingleChatSettingBinding.inflate(inflater);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = getIntent();
        friendDTO = (FriendDTO) intent.getSerializableExtra(KEY_FRIEND_DTO);
        settingDTO = (ChatPageSettingDTO) intent.getSerializableExtra(KEY_CHAT_PAGE_SETTING_DTO);

        initTitle();
        initViews();
    }

    public void initTitle() {
        TitleUtils.addTitleBarDynamic(binding.getRoot(), "聊天设置", v -> popPage());
    }

    public void initViews() {
        if (friendDTO != null) {
            ImageView leftIconIV = binding.menuFriendInfo.getLeftIconIV();
            Utils.setImageViewParams(leftIconIV, 50, 50);
            Glide.with(this)
                    .load(friendDTO.getAvatarUrl())
                    .apply(Utils.getRoundedCornersRequestOptions(5))
                    .into(leftIconIV);
            binding.menuFriendInfo.setLeftString(friendDTO.getNickname());
        }

        if (settingDTO != null) {
            binding.menuTopSetting.setSwitchIsChecked(settingDTO.getTop());
            binding.menuNotDisturbSetting.setSwitchIsChecked(settingDTO.getNotDisturb());
        }
    }
}
